import random

from moviepy.editor import *
from moviepy.video.compositing.transitions import crossfadeout, crossfadein, make_loopable, slide_out
from moviepy.video.fx.fadein import fadein
from moviepy.video.fx.fadeout import fadeout

input_1 = r'E:\songhq\video\transitions\zhongkong.mp4'
input_2 = r'E:\songhq\video\transitions\jiashishi.mp4'
outPath = r'E:\songhq\video\transitions\transition-slide_out.mp4'
outPath_2 = r'E:\songhq\video\transitions\transition-final_clip.mp4'
if __name__ == '__main__':
    video = VideoFileClip(input_1)
    video_2 = VideoFileClip(input_2)
    print("video 视频的长度为：" + str(video.duration))
    # fadein_video = fadein(video, 3)
    # fadein_video.write_videofile(filename=outPath, fps=24)
    # print("fadein_video 视频的长度为：" + str(fadein_video.duration))

    # crossfadein_video = make_loopable(video, 1)
    # crossfadein_video.write_videofile(filename=outPath, fps=24)
    # print("fadein_video 视频的长度为：" + str(crossfadein_video.duration))

    # 这样调用们没有效果
    # slide_out_video = slide_out(CompositeVideoClip([video]), 1, 'left')
    #
    # slide_out_video.write_videofile(filename=outPath, fps=24)
    # print("fadein_video 视频的长度为：" + str(slide_out_video.duration))
    #  转场的使用方法
    # clips = [video, video_2]
    # slided_clips = [CompositeVideoClip([
    #     clip.fx(transfx.slide_out, duration=2, side='left')])
    #     for clip in clips]
    # final_clip = concatenate(slided_clips, padding=-1)
    # final_clip.write_videofile(filename=outPath_2, fps=24)
    # print("final_clip 视频的长度为：" + str(final_clip.duration))
    #  转场的正确
    viedeo1 = CompositeVideoClip([video.fx(transfx.crossfadeout, duration=2)])
    viedeo1.write_videofile(filename=outPath, fps=24)
    print("fadein_video 视频的长度为：" + str(viedeo1.duration))
